package com.example.spring.boot.rabbitmq.configuration;

import com.example.spring.boot.rabbitmq.constant.DirectExchangeConstant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * 直连交换机配置类
 * </p>
 *
 * @author weixin
 * @date 2023/3/14 15:19
 */
@Configuration
public class DirectExchangeConfig implements BeanPostProcessor {

    /**
     * 直连队列
     * @return {@link Queue} 队列
     */
    @Bean
    public Queue directQueue() {
        return new Queue(DirectExchangeConstant.DIRECT_QUEUE, true);
    }

    /**
     * 直连队列2
     * @return {@link Queue} 队列
     */
    @Bean
    public Queue directQueue2() {
        return new Queue(DirectExchangeConstant.DIRECT_QUEUE2, true);
    }

    /**
     * 直连交换机
     * @return {@link DirectExchange} 队列
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DirectExchangeConstant.DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindingDirectExchange(Queue directQueue, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue)
                .to(directExchange)
                .with(DirectExchangeConstant.DIRECT_ROUTING_KEY);
    }

    @Bean
    public Binding bindingDirectExchange2(Queue directQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue2)
                .to(directExchange)
                .with(DirectExchangeConstant.DIRECT_ROUTING_KEY);
    }

}